# -*- coding: UTF-8 -*-
#cd /Users/wuchunlong/local/kjwy/python/disk-df

# 生成磁盘使用情况的日志文件
#(env375)$ python disk_log_file.py
# 2022-09-04[08/54/03].log
# Filesystem       Size   Used  Avail Capacity iused      ifree %iused  Mounted on
# /dev/disk1s5s1  466Gi   21Gi   61Gi    26%  553788 4882923132    0%   /
# devfs           187Ki  187Ki    0Bi   100%     646          0  100%   /dev
# /dev/disk1s4    466Gi  1.0Gi   61Gi     2%       2 4883476918    0%   /System/Volumes/VM
# /dev/disk1s2    466Gi  270Mi   61Gi     1%     801 4883476119    0%   /System/Volumes/Preboot
# /dev/disk1s6    466Gi  109Mi   61Gi     1%     394 4883476526    0%   /System/Volumes/Update
# /dev/disk1s1    466Gi  382Gi   61Gi    87% 4704776 4878772144    0%   /System/Volumes/Data
# /dev/disk1s5    466Gi   21Gi   61Gi    26%  553698 4882923222    0%   /System/Volumes/Update/mnt1

import time
import os

# python调用linux命令, 磁盘信息保存为文件
def disk_log():
	with open('%s.log' %time.strftime('%Y-%m-%d[%H:%M:%S]'), "w+") as f:
		f.write(''.join(os.popen('df -h').readlines())) #linux命令 df -h 显示已经挂载的分区列表 

if __name__ == "__main__":
	disk_log()
	
